(function ($) {
    /*
       titles编辑
    */
    $.fn.yqTitlesEdit = function (opts, param) {
        if (typeof opts == 'string') {
            return $.fn.yqTitlesEdit.methods[opts](this, param);
        }

        var $this = this;
        var opt;
        if ($this.data("yqtype") == "yqTitlesEdit") {
            var $uniqueID = $this.attr("ID");
            var opts_ = $.extend({}, options($this));
            destroy($this);
            if (opts.value === undefined) {
                opts.value = {};
            }
            if (opts.value.titles === undefined) {
                opts.value.titles = [];
            }
            if (opts.value.model === undefined) {
                opts.value.model = [];
            }
            $this = $("#" + $uniqueID);
            opt = $.extend(opts_, opts);
        }
        else {
            opt = $.extend({}, $.fn.yqTitlesEdit.defaults, opts);
            var $uniqueID = $this.attr("ID");
            if ($uniqueID === undefined || $uniqueID === null || $uniqueID == "") {
                $uniqueID = $.getUniqueID();
                $this.attr("ID", $uniqueID);
            }
        }

        if (opt.width === undefined && $this.width() > 0) {
            opt.width = $this.width();
        }
        if (opt.height === undefined && $this.height() > 0) {
            opt.height = $this.height();
        }

        //转换编辑尺寸
        if (typeof opt.width == "string") {
            var r_str = opt.width.substring(opt.width.length - 1, opt.width.length);
            if (r_str == "%") {
                var wSacle = parseInt(opt.width.substring(0, opt.width.length - 1));
                opt.width = parseInt(wSacle * $(window).width() / 100);
            } else {
                opt.width = parseInt(opt.width);
            }
        }
        if (typeof opt.height == "string") {
            var r_str = opt.height.substring(opt.height.length - 1, opt.height.length);
            if (r_str == "%") {
                var wSacle = parseInt(opt.height.substring(0, opt.height.length - 1));
                opt.height = parseInt(wSacle * $(window).height() / 100);
            } else {
                opt.height = parseInt(opt.height);
            }
        }

        //变量信息
        $this.data("titlesedit_opt", opt);
        $this.data("yqtype", "yqTitlesEdit");

        init_layout($this);
    };

    $.fn.yqTitlesEdit.defaults = {
        ajaxUrl: "/_db.html",
        // width: 900,
        // height: 700,
        value: {
            titles: [],
            model: []
        },
        isEdit: true,
        treeEdit: false,
    };

    $.fn.yqTitlesEdit.methods = {
        options: function (jq) {
            return options($(jq[0]));
        },
        resize: function (jq, params) {
            resize($(jq[0]), params);
        },
        setValue: function (jq, value) {
            setValue($(jq[0]), value);
        },
        clear: function (jq) {
            setValue($(jq[0]));
        },
        getValue: function (jq) {
            return getValue($(jq[0]));
        },
        setUiMaskValue: function (jq, param) {
            var opt = options($(jq[0]));
            opt.$div_mask.yqUiMaskEdit("setValue", param);
            if (param.isEdit) {
                opt.$div_mask.yqUiMaskEdit("isEdit", true);
            } else {
                opt.$div_mask.yqUiMaskEdit("isEdit", false);
            }
        },
        getUiMaskValue: function (jq) {
            var opt = options($(jq[0]));
            return opt.$div_mask.yqUiMaskEdit("getValue");
        },
        destroy: function (jq) {
            destroy($(jq[0]));
        },
        isEdit: function (jq, isedit) {
            isEdit($(jq[0]), isedit);
        }
    };

    function options($object) {
        return $object.data("titlesedit_opt");
    }

    function form_load($object) {
        resize($object);
    }

    function resize($object, params) {
        var opt = options($object);
        if (typeof params == "object") {
            if (typeof params.width != "undefined") {
                opt.width = params.width;
            }
            if (typeof params.height != "undefined") {
                opt.height = params.height;
            }
        }

        $object.find(".tb").css({
            width: opt.width + "px",
            height: opt.height + "px"
        });

        var w = opt.width - 2;
        var h = opt.height;

        var r_width = w * 0.4;
        if (r_width < 260) {
            r_width = 260;
        }

        opt.$div_titles.yqTableEdit("resize", {
            width: w - r_width,
            height: h
        });

        opt.$div_mask.yqUiMaskEdit("resize", {
            width: r_width,
            height: h - 134
        });

        opt.$div_model.datagrid("resize", {
            width: r_width,
            height: 132
        });
    }

    function destroy($object) {
        var opt = options($object);
        opt.$div_titles.yqTableEdit("destroy");
        opt.$div_mask.yqUiMaskEdit("destroy");
        var $dg = opt.$div_model.closest('div.datagrid');
        $dg.empty();
        $object.find(".tb").remove();

        $object.removeData("titlesedit_opt");
        $object.removeData("yqtype");
    }

    function isEdit($object, isedit) {
        var opt = options($object);
        var $uniqueID = $object.attr("id");
        opt.isEdit = isedit;
        opt.$div_titles.yqTableEdit("isEdit", isedit);
        opt.$div_mask.yqUiMaskEdit("isEdit", isedit);

        if (isedit) {
            $("#ui_toolbar_" + $uniqueID + "_add2").linkbutton("enable");
            $("#ui_toolbar_" + $uniqueID + "_add3").linkbutton("enable");
            $("#ui_toolbar_" + $uniqueID + "_del").linkbutton("disable");
        } else {
            $("#ui_toolbar_" + $uniqueID + "_add2").linkbutton("disable");
            $("#ui_toolbar_" + $uniqueID + "_add3").linkbutton("disable");
            $("#ui_toolbar_" + $uniqueID + "_del").linkbutton("disable");
        }
    }

    function getValue($object) {
        var opt = options($object);
        var titles = opt.$div_titles.yqTableEdit('getRows');
        var model = opt.$div_model.datagrid("getRows");
        //类型解耦
        var value = { titles: [], model: [] };
        for (let i = 0; i < titles.length; i++) {
            if (!titles[i].is_func) {
                delete titles[i].is_func;
            }
            value.titles.push($.extend({}, titles[i]));
        }
        for (let i = 0; i < model.length; i++) {
            value.model.push($.extend({}, model[i]));
        }
        return value;
    }

    function setValue($object, value) {
        var opt = options($object);
        if (value === undefined) {
            value = {};
        }
        if (value.titles === undefined) {
            value.titles = [];
        }
        if (value.model === undefined) {
            value.model = [];
        }

        //类型解耦
        var value2 = { titles: [], model: [] };
        for (let i = 0; i < value.titles.length; i++) {
            value2.titles.push($.extend({}, value.titles[i]));
        }
        for (let i = 0; i < value.model.length; i++) {
            value2.model.push($.extend({}, value.model[i]));
        }

        opt.$div_mask.yqUiMaskEdit("clear");
        opt.$div_titles.yqTableEdit('setRows', value2.titles);
        opt.$div_model.datagrid("loadData", { rows: value2.model });
    }

    function init_layout($object) {
        var opt = options($object);
        var $uniqueID = $object.attr("id");

        $object.append(`
    <table class="tb">
        <tr>
            <td  rowspan="2">
                <table class="tb_fields" style="width:100%;height: 500px;"></table>
            </td>
            <td>
                <table class="tb_ui_mask" style="width:100%;height: 500px;"></table>
            </td>
        </tr>
        <tr>
            <td>
                <table class="tb_ui" style="width:100%;height: 400px;"></table>
            </td>
        </tr>
    </table>
        `);

        opt.$div_titles = $object.find(".tb_fields");
        opt.$div_mask = $object.find(".tb_ui_mask");
        opt.$div_panel = $object.find(".div_ui");
        opt.$div_model = $object.find(".tb_ui");

        $object.find(".tb").css({
            width: opt.width + "px",
            height: opt.height + "px"
        });

        init_fields($object);
    }

    function init_fields($object) {
        var opt = options($object);
        var titles_set = [
            {
                "name": "is_func",
                "ui_title": "函数",
                "ui_type": 3,
                "ui_width": 40,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {
                    "default": false
                }
            }, {
                "name": "name",
                "ui_title": "字段名",
                "fd_type": "nvarchar",
                "length": 100,
                "decimal": 0,
                "ui_type": 2,
                "ui_width": 90,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {
                    "default": "",
                    "blank": false,
                    "format": null
                }
            }, {
                "name": "ui_title",
                "ui_title": "字段描述",
                "fd_type": "nvarchar",
                "length": 130,
                "decimal": 0,
                "ui_type": 2,
                "ui_width": 90,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {
                    "default": "",
                    "blank": false,
                    "format": null
                }
            }, {
                "name": "ui_type",
                "is_func": false,
                "ui_title": "UI类型",
                "fd_type": "int",
                "length": 16,
                "decimal": 0,
                "ui_type": 6,
                "ui_width": 135,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {
                    "default": 2,
                    "blank": false,
                    "lists": $.yqUiTypes(),
                    onChange: function (target, value) {
                        var newval = opt.$div_mask.yqUiMaskEdit("getValue");
                        opt.$div_mask.yqUiMaskEdit("setValue", { "ui_type": value, "value": newval });
                    }
                }
            }, {
                "name": "ui_width",
                "ui_title": "宽度",
                "fd_type": "int",
                "length": 10,
                "decimal": 0,
                "ui_type": 10,
                "ui_width": 80,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {
                    "default": "默认值",
                    "min": 10,
                    "max": 900,
                    "blank": false,
                    "format": "phone"
                }
            }, {
                "name": "ui_visible",
                "is_func": false,
                "ui_title": "ui可见",
                "fd_type": "boolean",
                "length": 1,
                "decimal": 0,
                "ui_type": 3,
                "ui_width": 50,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {
                    "default": true
                }
            }, {
                "name": "ui_readonly",
                "is_func": false,
                "ui_title": "只读",
                "fd_type": "boolean",
                "length": 1,
                "decimal": 0,
                "ui_type": 3,
                "ui_width": 40,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {
                    "default": false
                }
            }, {
                "name": "ui_mask",
                "is_func": false,
                "ui_title": "掩码",
                "fd_type": "nvarchar",
                "length": -1,
                "decimal": 0,
                "ui_type": 17,
                "ui_width": 130,
                "ui_visible": true,
                "ui_readonly": true,
                "ui_mask": {}
            }, {
                "name": "func",
                "ui_title": "函数表达式",
                "fd_type": "nvarchar",
                "length": 170,
                "decimal": 0,
                "ui_type": 2,
                "ui_width": 90,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {
                    "default": "",
                    "blank": false,
                    "format": null
                }
            }
        ];

        opt.$div_titles.yqTableEdit({
            ajaxUrl: "/_db.html",
            titles: titles_set,
            rows: opt.value.titles,
            //editModeW: 500, //模态编辑器宽度 格式为 800（数字）
            //editModeH: 180, //模态编辑器高度 格式为 600（数字）
            isEdit: opt.isEdit,
            toexcel: true,
            excelName: "titles导出",
            beforeBindingTitle: function (titles, callback) {
                for (let i = 0; i < titles.length; i++) {
                    if (titles[i].name == "ui_mask") {
                        titles[i].formatter = function (value, row, index) {
                            if (row.ui_type == 15 || row.ui_type == 16 || row.ui_type == 17) {
                                var value_ = JSON.parse(JSON.stringify(value));
                                delete value_.param;
                            } else {
                                var value_ = value;
                            }
                            return JSON.stringify(value_);
                        }
                    }
                }
                callback(titles);
            }, //标题绑定前
            afterBindingTitle: function () {
                init_uimask($object);
            },
            onClickRow: function (index, row) {
                opt.$div_mask.yqUiMaskEdit("setValue", { "ui_type": row["ui_type"], "value": row["ui_mask"] });
                if (row["ui_type"] == 15 ||
                    row["ui_type"] == 16 ||
                    row["ui_type"] == 17) {
                    opt.$div_model.datagrid("loadData", { "rows": row["ui_mask"].param.model === undefined ? [] : row["ui_mask"].param.model })
                }
            },
            endEditing: function (index, row) {
                var ui_mask = opt.$div_mask.yqUiMaskEdit("getValue");
                var row_ = $.extend({}, row);
                var value = opt.$div_mask.yqUiMaskEdit("getValue")
                if (typeof value == "string") {
                    value = JSON.parse(value);
                }
                row_["ui_mask"] = value;
                opt.$div_titles.yqTableEdit("updateRow", {
                    index: index,
                    row: row_,
                    isEdit: false
                });
                //console.log(ui_mask);
            },
            beforeAdd: function (rows, row, callback) {
                row["ui_type"] = 2;
                row["ui_width"] = 80;
                row["ui_visible"] = true;
                row["ui_mask"] = {};
                //console.log(rows, row);
                callback(row);
            },
        });
    }

    function init_uimask($object) {
        var opt = options($object);

        opt.$div_mask.yqUiMaskEdit({
            endEdit: function (index, row) {
                var _row = opt.$div_titles.yqTableEdit("getSelected");
                if (_row == null) {
                    return;
                }
                var index = opt.$div_titles.yqTableEdit("getSelectedIndex");
                var row_ = $.extend({}, _row);
                var value = opt.$div_mask.yqUiMaskEdit("getValue")
                if (typeof value == "string") {
                    value = JSON.parse(value);
                }
                row_["ui_mask"] = value;
                opt.$div_titles.yqTableEdit("updateRow", {
                    index: index,
                    row: row_,
                    isEdit: true
                });
            },
            isEdit: opt.isEdit,
            treeEdit: opt.treeEdit
        });

        init_tb_ui($object);
    }

    function init_tb_ui($object) {
        var opt = options($object);
        var $uniqueID = $object.attr("id");
        var ui_titles = [{
            "name": "no",
            "ui_title": "编码",
            "fd_type": "nvarchar",
            "length": 130,
            "decimal": 0,
            "ui_type": 10,
            "ui_width": 50,
            "ui_visible": true,
            "ui_readnnly": false,
            "ui_mask": {
                "default": "",
                "blank": false,
                "format": null
            }
        }, {
            "name": "type",
            "is_func": false,
            "ui_title": "类型",
            "fd_type": "int",
            "length": 16,
            "decimal": 0,
            "ui_type": 6,
            "ui_width": 90,
            "ui_visible": true,
            "ui_readnnly": false,
            "ui_mask": {
                "default": 2,
                "blank": false,
                "lists": [{ "no": 1, "name": "表格" },
                { "no": 2, "name": "Html模板" },
                { "no": 3, "name": "Code代码" }]
            }
        }, {
            "name": "describe",
            "ui_title": "描述",
            "fd_type": "nvarchar",
            "length": 130,
            "decimal": 0,
            "ui_type": 2,
            "ui_width": 200,
            "ui_visible": true,
            "ui_readnnly": false,
            "ui_mask": {
                "default": "",
                "blank": false,
                "format": null
            }
        }, {
            "name": "model",
            "is_func": false,
            "ui_title": "model",
            "fd_type": "boolean",
            "length": 1,
            "decimal": 0,
            "ui_type": 1,
            "ui_width": 300,
            "ui_visible": false,
            "ui_readnnly": false,
            "ui_mask": {}
        }];

        var dg_opt = {
            width: 800,
            height: 150,
            columns: $.yqDgColumns(ui_titles),
            data: { "rows": opt.value.model },
            onClickRow: function (index, row) {
                if (row === null || (!opt.isEdit)) {
                    $("#ui_toolbar_" + $uniqueID + "_del").linkbutton("disable");
                    $("#ui_toolbar_" + $uniqueID + "_upp").linkbutton("disable");
                } else {
                    $("#ui_toolbar_" + $uniqueID + "_del").linkbutton("enable");
                    $("#ui_toolbar_" + $uniqueID + "_upp").linkbutton("enable");
                }
            },

            rownumbers: true,
            fitColumns: false,

            scrollbarSize: 0,
            singleSelect: true,
            dragSelection: true,
        };

        var $ui_toolbar = $("<div></div>");
        $ui_toolbar.append('<a id="' + "ui_toolbar_" + $uniqueID + "_add2" + '"></a>');
        $ui_toolbar.append('<a id="' + "ui_toolbar_" + $uniqueID + "_add3" + '"></a>');
        $ui_toolbar.append('<a id="' + "ui_toolbar_" + $uniqueID + "_upp" + '"></a>');
        $ui_toolbar.append('<a id="' + "ui_toolbar_" + $uniqueID + "_del" + '"></a>');
        $object.append($ui_toolbar);
        dg_opt.toolbar = $ui_toolbar;
        $("#ui_toolbar_" + $uniqueID + "_add2").linkbutton({
            text: "Html",
            iconCls: "yqwin-btn-icon fa fa-file-code-o",
            plain: true,
            disabled: !opt.isEdit,
            onClick: function () {
                var rows = opt.$div_model.datagrid('getRows')
                var row = {};
                var action = "add";
                tb_ui_edit2($object, action, row);
            }
        });
        $("#ui_toolbar_" + $uniqueID + "_add3").linkbutton({
            text: "代码",
            iconCls: "yqwin-btn-icon fa fa-code",
            plain: true,
            disabled: !opt.isEdit,
            onClick: function () {
                var rows = opt.$div_model.datagrid('getRows')
                var row = {};
                var action = "add";
                tb_ui_edit3($object, action, row);
            }
        });
        $("#ui_toolbar_" + $uniqueID + "_upp").linkbutton({
            text: '修改',
            iconCls: 'yqwin-btn-icon fa fa-pencil-square',
            plain: true,
            disabled: true,
            onClick: function () {
                var row = opt.$div_model.datagrid("getSelected");
                if (!(row === null)) {
                    if (row["type"] == 2) {
                        tb_ui_edit2($object, "upp", row);
                    } else if (row["type"] == 3) {
                        tb_ui_edit3($object, "upp", row);
                    }
                }
            }
        });
        $("#ui_toolbar_" + $uniqueID + "_del").linkbutton({
            text: '删除',
            iconCls: 'yqwin-btn-icon fa fa-trash',
            plain: true,
            disabled: true,
            onClick: function () {
                var row = opt.$div_model.datagrid("getSelected");
                if (!(row === null)) {
                    opt.$div_model.datagrid("deleteRow", opt.$div_model.datagrid("getRowIndex"), row);
                    $("#ui_toolbar_" + $uniqueID + "_del").linkbutton("disable");
                }
            }
        });

        opt.$div_model.datagrid(dg_opt);

        form_load($object);
    }

    function tb_ui_edit2($object, action, row) {
        var opt = options($object);

        var titles_ = $.yqFmUiTitle(opt.$div_titles.yqTableEdit("getRows"));
        if (action == "add") {
            row["describe"] = "Html模板";
            row["model"] = "";
            row["type"] = 2;
        }

        var _pops = {
            title: "Html模板",
            onOpen: function ($body) {
                $body.css({ "border-width": 0 });
                var w = $body.width();
                var h = $body.height();
                $body.append(`
                    <table style="width:100%;">
                        <tr>
                            <td width="160px;" style="padding:3px 0px 3px 5px;">
                                <input name="txt_no" style="width:140px;"/>
                            </td>  
                            <td style="padding:3px 0px 3px 5px;">
                                <input name="txt_describe" style="width:220px;"/>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4">
                                <div name="txt_model" style="width:100%;height:100%;"></div>
                            </td>
                        </tr>
                    </table>
                `);

                var $no = $body.find("[name='txt_no']");
                var $describe = $body.find("[name='txt_describe']");
                var $tb = $body.find("[name='txt_model']");

                $no.numberspinner({
                    label: "编码",
                    labelWidth: 35,
                    labelPosition: "before",
                    min: 0,
                    max: 9999,
                    value: row["no"]
                });

                $describe.textbox({
                    label: "描述",
                    labelWidth: 35,
                    labelPosition: "before",
                    value: row["describe"]
                });

                $tb.yqTmplHtmlEdit({
                    isEdit: true,
                    width: w - 2,
                    height: h - 80,
                    titles: titles_,
                    value: row["model"]
                });
            },
            buttons: [{
                text: "确定",
                iconCls: 'icon-ok',
                onClick: function ($body) {
                    var $no = $body.find("[name='txt_no']");
                    var $describe = $body.find("[name='txt_describe']");
                    var $tb = $body.find("[name='txt_model']");

                    var value_ = $tb.yqTmplHtmlEdit("getValue");
                    row = $.extend({}, row);

                    row["no"] = $.yqToInt($no.val());
                    row["describe"] = $describe.val();
                    row["model"] = value_;

                    if (action == "add") {
                        opt.$div_model.datagrid("appendRow", row);
                    } else if (action == "upp") {
                        var s_row = opt.$div_model.datagrid("getSelected");
                        if (s_row === null) {
                            opt.$div_model.datagrid("appendRow", row);
                            return;
                        }

                        opt.$div_model.datagrid("updateRow", {
                            index: opt.$div_model.datagrid("getRowIndex", s_row),
                            row: row
                        });
                    }

                    this.dialog("close");
                }
            }],
        };

        if (window.top == window.self) {
            var w_ = $(window).width();
            if (w_ > 1200) {
                w_ = 1200;
            }
            _pops.width = w_;
            _pops.height = $(window).height() - 30;

            $.yqDialog(_pops);
        }
        else {
            var w_ = $(window.top).width();
            if (w_ > 1200) {
                w_ = 1200;
            }
            _pops.width = w_;
            _pops.height = $(window.top).height() - 30;

            window.top.$.yqDialog(_pops);
        }
    }

    function tb_ui_edit3($object, action, row) {
        var opt = options($object);

        if (action == "add") {
            row["type"] = 3;
            row["describe"] = "代码程序";
            row["model"] = "";
        }

        var _pops = {
            title: "Code编辑",
            onOpen: function ($body) {

                var w = $body.width();
                var h = $body.height();
                $body.append(`
                    <table style="width:100%;">
                        <tr>
                            <td width="160px;" style="padding:3px 0px 3px 5px;">
                                <input name="txt_no" style="width:140px;"/>
                            </td>  
                            <td style="padding:3px 0px 3px 5px;">
                                <input name="txt_describe" style="width:220px;"/>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4">
                                <textarea name="txt_model" style="width:100%;height:100%;"></textarea>
                            </td>
                        </tr>
                    </table>
                `);

                var $no = $body.find("[name='txt_no']");
                var $describe = $body.find("[name='txt_describe']");
                var $tb = $body.find("[name='txt_model']");

                $no.numberspinner({
                    label: "编码",
                    labelWidth: 35,
                    labelPosition: "before",
                    min: 0,
                    max: 9999,
                    value: row["no"]
                });

                $describe.textbox({
                    label: "描述",
                    labelWidth: 35,
                    labelPosition: "before",
                    value: row["describe"]
                });

                var model = row["model"];
                var m_type = "javascript";
                var m_value = "";
                if (!(model === undefined || model === null || model == "")) {
                    model = JSON.parse(model);
                    m_type = model.type;
                    m_value = model.value;
                }

                $tb.yqCodeEdit({
                    types: ["html", "javascript", "css"],
                    type: m_type,
                    value: m_value,
                    isEdit: true,
                    width: w - 2,
                    height: h - 81,
                });


            },
            buttons: [{
                text: "确定",
                iconCls: 'icon-ok',
                onClick: function ($body) {
                    var $no = $body.find("[name='txt_no']");
                    var $describe = $body.find("[name='txt_describe']");
                    var $tb = $body.find("[name='txt_model']");

                    var value_ = {
                        type: $tb.yqCodeEdit("getType"),
                        value: $tb.yqCodeEdit("getValue")
                    };

                    row = $.extend({}, row);
                    row["no"] = $no.val();
                    row["describe"] = $describe.val();
                    row["model"] = JSON.stringify(value_);

                    if (action == "add") {
                        opt.$div_model.datagrid("appendRow", row);
                    } else if (action == "upp") {
                        var s_row = opt.$div_model.datagrid("getSelected");
                        if (s_row === null) {
                            opt.$div_model.datagrid("appendRow", row);
                            return;
                        }

                        opt.$div_model.datagrid("updateRow", {
                            index: opt.$div_model.datagrid("getRowIndex", s_row),
                            row: row
                        });
                    }

                    this.dialog("close");
                }
            }],
        };

        if (window.top == window.self) {
            var w_ = $(window).width();
            if (w_ > 1200) {
                w_ = 1200;
            }
            _pops.width = w_;
            _pops.height = $(window).height() - 30;

            $.yqDialog(_pops);
        }
        else {
            var w_ = $(window.top).width();
            if (w_ > 1200) {
                w_ = 1200;
            }
            _pops.width = w_;
            _pops.height = $(window.top).height() - 30;

            window.top.$.yqDialog(_pops);
        }
    }
})(jQuery);